﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using AccessDAL;
using DBUtility;

namespace web
{
    public partial class list : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string sql = "";
                sql = "SELECT count(id) FROM menu ";
                int totalOrders = Convert.ToInt32(MySqlHelper.GetSingle(sql));               
                AspNetPager1.RecordCount = totalOrders;
                bindDL();
            }
        }


      
        private void bindDL()
        {
            string sql = "";
            int pageSize = AspNetPager1.PageSize;
            sql = "SELECT * from menu  as m order by m.ID desc limit " + AspNetPager1.StartRecordIndex + "," + pageSize;
            DataSet dt = MySqlHelper.Query(sql);
            this.GridView1.DataSource = dt;
            this.GridView1.DataBind();
           
            //lblPage.Text = "第"+AspNetPager1.CurrentPageIndex.ToString() + "页 共" + AspNetPager1.PageCount.ToString() + "页   第 " + AspNetPager1.StartRecordIndex.ToString() + "-" + AspNetPager1.EndRecordIndex.ToString() + "条记录  共" + AspNetPager1.RecordCount.ToString() + "条记录";
            dt.Dispose();
        }

       

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bindDL();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                //if (e.Row.RowType == DataControlRowType.DataRow)
                //{
                //    //当鼠标停留时更改背景色
                //    e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#d7e3f6'");
                //    //当鼠标移开时还原背景色
                //    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                //}
            }
           
        }

        protected void btnShowID_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                CheckBox cb = (CheckBox)(GridView1.Rows[i].FindControl("CheckSingle"));
                string menuId = "0";
                if (cb.Checked)
                {
                    menuId = GridView1.DataKeys[i]["id"].ToString();
                }
                Response.Write(menuId);
            }
            
        }

       
    }
}
